package com.todo.pro.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.todo.pro.storage.FileStorage;
import com.todo.pro.util.IpUtils;
import com.todo.pro.web.domain.AjaxResult;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author SiZhongxia
 * @since 2017-12-27
 */
@Controller
@RequestMapping("/")
public class IndexController {
	private final Logger logger = LoggerFactory.getLogger(IndexController.class);

	@Autowired
	private FileStorage fileStorage;

	@ResponseBody
	@RequestMapping(value = { "/index" })
	public AjaxResult index(HttpServletRequest request) {
		return AjaxResult.success();
	}

	@ResponseBody
	@RequestMapping(value = { "/fileStorage/qiniu/token" })
	public AjaxResult qiniuToken(HttpServletRequest request) {
		return AjaxResult.success().put("upToken", fileStorage.initUpToken());
	}

	@ResponseBody
	@RequestMapping(value = { "/printLog" })
	public AjaxResult printLog(HttpServletRequest request) {
		logger.info("MPLOG >>>> IP:" + IpUtils.getIpAddr(request));
		logger.info("MPLOG >>>> PAGE:" + request.getParameter("pageName"));
		return AjaxResult.success();
	}

}
